package com.Dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.pojo.ShopNews;



public class ShopDao {
	private int shopCount;
	private int shopCountX;
	static {//瀵煎叆MySql椹卞姩鍖�
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {}
	}
	private Connection getConn() throws SQLException {
		String url = "jdbc:mysql://localhost:3306/hi_db" + "?useUnicode=true&characterEncoding=UTF-8";
		String username = "root";
		String password = "15723";
		Connection conn = DriverManager.getConnection(url, username, password);
		return conn;
	}

	
	public ShopNews[] finduser() throws SQLException {
		//1.鍒涘缓杩炴帴
		Connection conn = getConn();//璋冪敤涓婇潰鐨勬柟娉�
		//2.鍒涘缓鎵ц鍧�
		Statement st = conn.createStatement();
		//SQL
		String sql = "SELECT  * FROM  user where Uid is not null";
				
		ResultSet rs = st.executeQuery(sql);
		ShopNews[] shopArrX = new ShopNews[100];
		this.shopCountX = 0;//杩樺師鍥句功鏁伴噺
		while(rs.next()) {
		ShopNews book = new ShopNews(
				rs.getInt("uid"),
				rs.getString("uname"),
				rs.getString("uphone"),
		        rs.getString("uemail"),
		        rs.getString("uage"),
		        rs.getString("usex"),
		        rs.getString("ujst")
		        );
		shopArrX[shopCountX] = book;
		shopCountX++;
	}
		rs.close();
		st.close();//鍏抽棴鎵ц鍧�
		conn.close();//鍏抽棴杩炴帴
	
	return shopArrX;
	}
	
	
	
	
	

	public int getShopCountX() {
		return shopCountX;
	}

	
	public Integer Updateuaer(Integer Uid,String Ujst) throws SQLException {
		//1銆佸垱寤鸿繛鎺�
		Connection conn = getConn();
		//2銆佸垱寤哄鐞嗗潡
		Statement st = conn.createStatement();
		//3銆佺紪鍐檚ql
		String sql = "UPDATE  user set Ujst='"+ Ujst+"'  where Uid ='"+Uid+"'";
		Integer result = st.executeUpdate(sql);
		//5銆佸叧闂墽琛屽潡
		st.close();
		//6銆佸叧闂繛鎺�
		conn.close();
		return result;
		
	}
	public Integer Update(String Uphone,String Upsw,String Urpsw) throws SQLException {
		//1銆佸垱寤鸿繛鎺�
		Connection conn = getConn();
		//2銆佸垱寤哄鐞嗗潡
		Statement st = conn.createStatement();
		//3銆佺紪鍐檚ql
		String sql = "UPDATE  user set Upsw='"+ Upsw+"',Urpsw='"+ Urpsw+"'  where Uphone ='"+Uphone+"'";
		Integer result = st.executeUpdate(sql);
		//5銆佸叧闂墽琛屽潡
		st.close();
		//6銆佸叧闂繛鎺�
		conn.close();
		return result;
		
	}


	
	
		}
	

